<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>商品品牌</title>
    <!--{include file='comm/comm_editor.tpl'}-->
</head>

<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="ebsig_container">

    <!--{include file='comm/menu.tpl'}-->
    <div class="comm_content">

        <div class="search-box">
            <div style="position:relative">
                <form id="search_form" onsubmit="return false;">
                    <table>
                        <tbody>
                            <tr>
                                <td height="27px">
                                    <span>品牌名称：<input type="text"  name="brandName" value="" /></span>
                                    <span><input type="button" value="查询" class="btn" onclick="brand.search();" /></span>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>

        <table id="flex" style="display:none"></table>
    </div>

</div>

<div id ="pop" style="display: none;">

    <div style="width:100%; background: #ffffff">
        <form id = "brand_form" onsubmit="return false;">
            <div class="input-group input-group-lg"  >
                <span class="input-group-addon">品牌名称：</span>
                <input class="form-control"  type="text" id="brandName" name="brandName" maxlength="20" placeholder="请输入品牌名称 【必填项】"  value="" />
            </div>

            <div class="input-group input-group-lg">
                <span class="input-group-addon">品牌描述</span>
                <textarea class="input-group-textarea" name="description" id="n_description" placeholder="请输入品牌描述"></textarea>
            </div>

            <div class="input-group input-group-lg"  >
                <span class="input-group-addon">排列序号：</span>
                <input class="form-control"  type="text" id="sortOrder" name="sortOrder" maxlength="6"  placeholder="请输入排列序号 【必填项】" />
            </div>

            <div class="input-group input-group-lg" style="height:100px;" >
                <span class="input-group-addon">上传logo：</span>
                <div id="pic_div" style="border: 1px solid #CCCCCC;height: 100px;width: 100px; float: left">
                    <img id="img_logo" height="100px" width="100px" src="" />
                </div>
                <div style="margin-top: 35px; margin-left: 10px; float: left">
                <input type="button" class="btn" value="上传logo"  id="upload_img" /><br/>
                <input type="button" class="btn" value="清空logo" style="margin-top: 10px;" onclick="brand.reLogo();" />
                <input type="hidden" name="brand_img" id="brand_img" value="" />
                </div>
                <input type="hidden" name="useFlg" id="useFlg" value="1" />
                <input type="hidden" name="brandID" id="brandID" value="" />
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
$("#flex").flexigrid({
    url:"/invokingAjax-backend/goods/brand.ajax?operFlg=1&xjx=none",
    dataType: "json",
    colModel : [
        <!--{if $edit_permission}-->
        {display: "操作", width : 100, align: "center"},
        <!--{/if}-->
        {display: "品牌名称", width : 280},
        {display: "品牌描述", width : 280},
        {display: "排列序号", width : 100, name : "sortOrder",sortable : true},
        {display: "使用状态", width : 100 , align: "center"}
        
    ],
    <!--{if $edit_permission}-->
    buttons : [
        {name: "添加", bclass: "add", onpress : "brand.edit"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "brand.del.check"}
        ],
        <!--{/if}-->
        sortname: "sortOrder",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var brand = {

        //搜索品牌
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        deleteBrand: function() {
            this.delete_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    brand.delete_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.delete_str == "")
                E.alert("请选择删除品牌");
            else
                E.confirm("您确认要删除选中的品牌吗？", "brand.deleteConfirm");
        },

        change: {

            check: function( brandID , useFlg ) {
                this.brandID = brandID;
                this.useFlg = useFlg;
                if( useFlg == 0 ) {
                    brand.change.execute();
                } else {
                    E.confirm("您确认要禁用此商品品牌吗？", "brand.change.execute");
                }
            },

            execute: function() {
                E.loadding.open('请稍候...');
                E.ajax_get({
                    url: '/invokingAjax-backend/goods/brand.ajax?operFlg=5',
                    data: {
                        brandID: this.brandID
                    },
                    call: 'brand.change.result'
                });
            },

            result: function( o ) {

                E.loadding.close();
                if (o.code == 200) {
                    E.alert(o.message, 2, 'brand.load');
                } else {
                    E.alert(o.message)
                }

            }

        },

        del: {

            b_array: new Array(),

            check: function() {

                var b_obj = $('#flex').find('tr.trSelected');
                if (b_obj.length == 0) {
                    E.alert('请选择要删除的商品品牌');
                } else {

                    var temp_array = new Array();

                    $.each(b_obj, function(k, v) {
                        var id = $(v).attr('id').replace('row', '');
                        temp_array.push($(v).attr('id').replace('row', ''));
                    });

                    this.b_array = temp_array;
                    E.confirm('您确认要删除选中的商品品牌吗？', 'brand.del.execute');

                }

            },

            execute: function() {

                E.loadding.open('请稍候...');
                E.ajax_post({
                    url: '/invokingAjax-backend/goods/brand.ajax?operFlg=4',
                    data: {
                        b_array: this.b_array
                    },
                    call: 'brand.del.result'
                });

            },

            result: function( o ) {

                E.loadding.close();
                if (o.code == 200) {
                    E.alert('商品品牌删除成功', 2, 'brand.load');
                } else {
                    E.alert(o.message);
                }

            }

        },

        //查询待编辑信息
        edit: function(brandID) {
           E.loadding.open("请稍后...");
           var name="";
            if(brandID){
                name="修改商品品牌";
                E.ajax_get({
                    url: "/invokingAjax-backend/goods/brand.ajax?operFlg=6",
                    data:{brandID:brandID},
                    call: "brand.val"
                });
            }else{
                name="添加商品品牌";
                E.ajax_get({
                    url:"/invokingAjax-backend/goods/brand.ajax?operFlg=7",
                    data:"",
                    call:"brand.reSort"
                });
            }

            E.popup.open({
                id:"pop",
                title: name,
                content: "",
                css: "width:960px;",
                btnName: "保存",
                btnCall:"brand.check();"
            });
        },

        //重置Logo
        reLogo: function(){
            $("#pic_div").html('');
            $("#brand_img").val('');
            $("#img_logo").attr("src",null) ;
        },

        //编辑弹出框赋值
        val: function(o) {
            E.loadding.close();

            $("#brandName").val(o.brandName);
            $("#brandID").val(o.brandID);
            $("#sortOrder").val(o.sortOrder);
            $("#useFlg").val(o.useFlg);
            $("#n_description").val(o.description);
            $("#brand_img").val(o.brand_img);
            $("#img_logo").attr("src", o.logo) ;
        },

        load: function() {
            $("#flex").flexReload();
        },

        brandID:"",
        sortOrder:"",
        //检查数据
        check: function() {

            var dt = E.getFormValues("brand_form");

            var error_msg = "";
            if (dt.brandName == "")
                error_msg += "品牌名称不能为空<br />";

            if (!E.isInt(dt.sortOrder))
                error_msg += "排序序号必须为数字<br />";

            if (error_msg != "") {
                E.alert(error_msg);
            } else {
                E.ajax_post({
                    url: '/invokingAjax-backend/goods/brand.ajax?operFlg=2',
                    data: dt,
                    call: 'brand.result'
                });
            }

        },

        result: function( o ) {

            this.brandID = $("#brandID").val();
            this.sortOrder =$("#sortOrder").val();
            if (o.code == 200) {
                brand.load();
                if (this.brandID) {
                    E.alert(o.message, 2, "E.popup.close");
                } else {
                    var sort = ++this.sortOrder;
                    $("#sortOrder").val(sort);
                    E.alert(o.message, 2, "brand.reset");
                }

            } else {

                E.alert(o.message);

            }

        },


        //清除商品信息
        reset: function() {
            $("#brandName").val("");
            $("#n_description").val("");
            $("#pic_div").html("");
            $("#brand_img").val("");
            },

        //重置序列号
        reSort: function(o){
			E.loadding.close();
            $("#sortOrder").val(o.sortOrder);
        }

    };

    KindEditor.ready(function(K) {
        var editor = K.editor({
            allowFileManager : true,
            uploadJson: '/framework/kindeditor/php/upload_json.php?act=userdefined'
        });
        $(document).on('click', '#upload_img', function() {
            editor.loadPlugin('image', function() {
                editor.plugin.imageDialog({
                    showRemote : false,
                    clickFn : function(url) {
                        $("#brand_img").val(url);
                        $("#pic_div").html('<img src="' + url + '" style="width:100px;height:100px; float: left;" />');
                        editor.hideDialog();
                    }
                });
            });
        });
    });
</script>

</body>

</html>
